import 'package:flutter/material.dart';
import './model/post.dart';
import 'drawer_demo.dart';
import 'bottom_navigation_bar_demo.dart';
import 'based_demo.dart';
import 'layout_demo.dart';
import 'view_demo.dart';
import 'sliver_demo.dart';


//SlverGrid SliverList
void main() => runApp(MyApp());



class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Home(),
      theme: ThemeData(
        primaryColor: Colors.white
      ),
    );
  }
}

class Home extends StatelessWidget{


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    
//    return ListViews();
  
     return DefaultTabController(
         length: 4,
         child: Scaffold(
           backgroundColor: Colors.grey[100],
           appBar: AppBar(
             title: Text('WANGSONGFEMNG'),
             actions: <Widget>[

             ],
             elevation: 0.0,
             bottom: TabBar(
               unselectedLabelColor: Colors.black45,
               indicatorColor: Colors.black54,
               indicatorSize: TabBarIndicatorSize.label,
               tabs: <Widget>[
                 Tab(
                   icon: Icon(Icons.message),
                 ),
                 Tab(
                   icon: Icon(Icons.directions_run),
                 ),
                 Tab(
                   icon: Icon(Icons.dialer_sip),
                 ),
                 Tab(
                   icon: Icon(Icons.date_range),
                 )
               ],
             ),

           ),
           body: TabBarView(
              children: <Widget>[
                ListViews(),
                BasicDemo(),
                LayoutDemo(),
                SliverDemo()
              ],
           ),
           drawer: DrawerDemo(),
           bottomNavigationBar: BottomNavigationBarDemo(),
           
         )
     );
  }
}

//ListView的布局
class ListViews extends StatelessWidget{

  Widget _listItemBuilder(BuildContext context,int index){
    return Container(
      color: Colors.white,
      margin: EdgeInsets.all(8.0),
      child: Column(
        children: <Widget>[
          Image.network(posts[index].imageUrl),
          SizedBox(height: 16.0),
          Text(
            posts[index].title,
            style: Theme.of(context).textTheme.title,
          ),
          Text(
            posts[index].author,
            style: Theme.of(context).textTheme.title,
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
//        appBar: AppBar(
//          title: Text('Hello World'),
//          elevation: 0.0,
//        ),
        body: ListView.builder(
          itemCount: posts.length,
          itemBuilder: _listItemBuilder,
        )
    );
  }
}

class Hello extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      child: Text(
        'hello',
        textDirection: TextDirection.ltr,
        style: TextStyle(
          fontSize: 40.0,
          fontWeight: FontWeight.bold,
          color: Colors.yellow,
        ),
      ),
    );
  }
}